import type { App } from 'vue';
import { baseMessage, showMessage, message } from '@/utils/message';
import type { MessageOptions } from '@/components/BaseMessage.vue';

// 声明全局属性类型
declare module '@vue/runtime-core' {
  interface ComponentCustomProperties {
    $baseMessage: (message: string, type?: 'success' | 'error' | 'warning' | 'info', options?: Partial<MessageOptions>) => void;
    $message: {
      success: (msg: string, options?: Partial<MessageOptions>) => void;
      error: (msg: string, options?: Partial<MessageOptions>) => void;
      warning: (msg: string, options?: Partial<MessageOptions>) => void;
      info: (msg: string, options?: Partial<MessageOptions>) => void;
    };
    $showMessage: (message: string, type?: 'success' | 'error' | 'warning' | 'info', options?: Partial<MessageOptions>) => void;
    $showSuccess: (msg: string, options?: Partial<MessageOptions>) => void;
    $showError: (msg: string, options?: Partial<MessageOptions>) => void;
  }
}

export default {
  install(app: App) {
    // 注册 $baseMessage 方法
    app.config.globalProperties.$baseMessage = baseMessage;

    // 注册 $showMessage 方法
    app.config.globalProperties.$showMessage = showMessage;

    // 注册 $message 快捷方法
    app.config.globalProperties.$message = message;

    // 注册 $showSuccess 和 $showError 快捷方法
    app.config.globalProperties.$showSuccess = (msg: string, options?: Partial<MessageOptions>) => {
      message.success(msg, options);
    };

    app.config.globalProperties.$showError = (msg: string, options?: Partial<MessageOptions>) => {
      message.error(msg, options);
    };
  }
}; 